package com.sright.bcard.mini.web.context;

import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * @author peter
 * @description
 * @date 2020/6/2
 */
public class RequestStorager {

    final private static ThreadLocal<ServletContext> requestContext = new TransmittableThreadLocal<>();

    public static Long getUserId() {
        ServletContext servletContext = requestContext.get();
        if (servletContext == null) {
            return null;
        }
        return servletContext.getUserId();
    }

    public static void setUserId(Long userId) {
        ServletContext servletContext = requestContext.get();
        if (servletContext == null) {
            servletContext = new ServletContext();
            requestContext.set(servletContext);
        }
        servletContext.setUserId(userId);
    }


    public static Long getMemberId() {
        ServletContext servletContext = requestContext.get();
        if (servletContext == null) {
            return null;
        }
        return servletContext.getMemberId();
    }

    public static void setMemberId(Long memberId) {
        ServletContext servletContext = requestContext.get();
        if (servletContext == null) {
            servletContext = new ServletContext();
            requestContext.set(servletContext);
        }
        servletContext.setMemberId(memberId);
    }

    public static Long getEnterpriseId() {
        ServletContext servletContext = requestContext.get();
        if (servletContext == null) {
            return null;
        }
        return servletContext.getEnterpriseId();
    }

    public static void setEnterpriseId(Long enterpriseId) {
        ServletContext servletContext = requestContext.get();
        if (servletContext == null) {
            servletContext = new ServletContext();
            requestContext.set(servletContext);
        }
        servletContext.setEnterpriseId(enterpriseId);
    }

    public static Integer getIsAuthorize() {
        ServletContext servletContext = requestContext.get();
        if (servletContext == null) {
            return null;
        }
        return servletContext.getIsAuthorize();
    }

    public static void setIsAuthorize(Integer isAuthorize) {
        ServletContext servletContext = requestContext.get();
        if (servletContext == null) {
            servletContext = new ServletContext();
            requestContext.set(servletContext);
        }
        servletContext.setIsAuthorize(isAuthorize);
    }
}
